{% extends 'generic/object_retrieve.html' %}
{% load helpers %}

{% block content_left_page %}
    <div class="card">
        <div class="card-header">
            <strong>Console Port</strong>
        </div>
        <table class="table table-hover card-body attr-table">
            <tr>
                {% if object.device %}
                    <td>Device</td>
                    <td>{{ object.device|hyperlinked_object }}</td>
                {% else %}
                    <td>Module</td>
                    <td>{{ object.module|hyperlinked_object }}</td>
                {% endif %}
            </tr>
            <tr>
                <td>Name</td>
                <td>{{ object.name }}</td>
            </tr>
            <tr>
                <td>Label</td>
                <td>{{ object.label|placeholder }}</td>
            </tr>
            <tr>
                <td>Type</td>
                <td>{{ object.get_type_display }}</td>
            </tr>
            <tr>
                <td>Description</td>
                <td>{{ object.description|placeholder }}</td>
            </tr>
        </table>
    </div>
{% endblock content_left_page %}

{% block content_right_page %}
    <div class="card">
        <div class="card-header">
            <strong>Connection</strong>
        </div>
        {% if object.cable %}
            <table class="table table-hover card-body attr-table">
                <tr>
                    <td>Cable</td>
                    <td>
                        {{ object.cable|hyperlinked_object }}
                        <a href="{% url 'dcim:consoleport_trace' pk=object.pk %}" class="btn btn-primary btn-sm" title="Trace">
                            <span class="mdi mdi-transit-connection-variant" aria-hidden="true"></span>
                        </a>
                    </td>
                </tr>
                {% if object.connected_endpoint %}
                    <tr>
                        {% if object.connected_endpoint.device %}
                            <td>Device</td>
                            <td>{{ object.connected_endpoint.device|hyperlinked_object }}</td>
                        {% else %}
                            <td>Module</td>
                            <td>{{ object.connected_endpoint.module|hyperlinked_object }}</td>
                        {% endif %}
                    </tr>
                    <tr>
                        <td>Console Server Port</td>
                        <td>{{ object.connected_endpoint|hyperlinked_object }}</td>
                    </tr>
                    <tr>
                        <td>Type</td>
                        <td>{{ object.connected_endpoint.get_type_display|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Description</td>
                        <td>{{ object.connected_endpoint.description|placeholder }}</td>
                    </tr>
                    <tr>
                        <td>Path Status</td>
                        <td>
                            {% if object.path.is_active %}
                                <span class="badge bg-success">Reachable</span>
                            {% else %}
                                <span class="badge bg-danger">Not Reachable</span>
                            {% endif %}
                        </td>
                    </tr>
                {% endif %}
            </table>
        {% else %}
            <div class="card-body text-secondary">
                Not connected
                {% if perms.dcim.add_cable %}
                    <span class="dropdown float-end">
                        {# comment The "fixed" strategy allows the dropdown to break out of the containing card #}
                        <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-bs-popper-config='{"strategy": "fixed"}'>
                            <span class="mdi mdi-ethernet-cable" aria-hidden="true"></span> Connect
                        </button>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='console-server-port' %}?return_url={{ object.get_absolute_url }}">Console Server Port</a></li>
                            <li><a class="dropdown-item" href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='front-port' %}?return_url={{ object.get_absolute_url }}">Front Port</a></li>
                            <li><a class="dropdown-item" href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='rear-port' %}?return_url={{ object.get_absolute_url }}">Rear Port</a></li>
                        </ul>
                    </span>
                {% endif %}
            </div>
        {% endif %}
    </div>
{% endblock content_right_page %}
